package service.impl;

import Dao.TrainDao;
import Dao.impl.TrainDaoImpl;
import entity.TrainVehicleInfo;
import service.TrainService;
import untils.Msg;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Scanner;



public class TrainServiceImpl implements TrainService {
    private TrainDao trainDao = new TrainDaoImpl();
    static Scanner sc = new Scanner(System.in);
    @Override
    public void viewTrainM() {
        ArrayList<TrainVehicleInfo> trainVehicleInfos = trainDao.viewTrainM();
        for (int i = 0;i<trainVehicleInfos.size();i++){
            System.out.println(i+"\t"+trainVehicleInfos.get(i).show());
        }
    }

    @Override
    public void perfectTrainM() {
        ArrayList<TrainVehicleInfo> trainVehicleInfos = trainDao.viewTrainM();
        System.out.println("选择你要管理的列车名称");
        int select = sc.nextInt();
        TrainVehicleInfo t= trainVehicleInfos.get(select);
        System.out.println("输入车辆类型：");
        t.setCarType(sc.next());
        System.out.println("输入制造商：");
        t.setMakeProduct(sc.next());
        System.out.println("输入制造日期：");
        t.setMakeDate(Date.valueOf(sc.next()));
        System.out.println("输入当前状态：(使用中，维修中，待报废)");
        t.setCurrentStatus(sc.next());
        System.out.println("所属铁路局");
        t.setRailwaybureau(sc.next());
        System.out.println("载重量（货车）");
        t.setCapacity(sc.nextInt());
        System.out.println("上次维护时间");
        t.setLastMaintenanceDate(Date.valueOf(sc.next()));
        trainDao.perfectTrainM(t);
        System.out.println(Msg.msg);
    }

    @Override
    public void updateTrainM() {
        ArrayList<TrainVehicleInfo> trainVehicleInfos = trainDao.viewTrainM();
        for (int i = 0;i<trainVehicleInfos.size();i++){
            System.out.println(i+"\t"+trainVehicleInfos.get(i).show());
        }
        System.out.println("选择你要管理的列车名称");
        int select = sc.nextInt();
        TrainVehicleInfo t= trainVehicleInfos.get(select);
        System.out.println("输入当前状态：(使用中，维修中，待报废)");
        t.setCurrentStatus(sc.next());
        System.out.println("所属铁路局");
        t.setRailwaybureau(sc.next());
        System.out.println("上次维护时间");
        t.setLastMaintenanceDate(Date.valueOf(sc.next()));
        trainDao.updateTrainM(t);
        System.out.println(Msg.msg);
    }

    @Override
    public void deleteTrainM() {
        ArrayList<TrainVehicleInfo> trainVehicleInfos = trainDao.viewTrainM();
        for (int i = 0;i<trainVehicleInfos.size();i++){
            System.out.println(i+"\t"+trainVehicleInfos.get(i).show());
        }
        System.out.println("选择你要管理的列车名称");
        int select = sc.nextInt();
        TrainVehicleInfo t= trainVehicleInfos.get(select);
        trainDao.deleteTrainM(t.getCarId());
        System.out.println(Msg.msg);
    }
}
